package com.email.box.common.enums;

import com.email.box.common.vo.ApiResultCode;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * @author lixuan
 */

public enum DefaultApiResultCode implements ApiResultCode {
    //返回参数枚举类
    G400(400, "错误的请求参数"),
    G401(401, "认证失败"),
    G404(404, "此API不存在"),
    G405(405, "请求方式错误"),
    G500(500, "API异常"),
    G504(504, "API请求超时"),
    G1001(1001, "此次请求没有查询到相应内容"),
    G1002(1002, "超过API单小时最大请求次数"),
    G1003(1003, "APP KEY无效"),
    G1004(1004, "此API已禁用"),
    G1005(1005, "有恶意访问嫌疑"),
    G1006(1006, "没有API业务访问权限"),
    G1007(1007, "此API访问权限已到期"),
    G1008(1008, "无效API业务"),
    G1009(1009, "请求已过期"),
    G1100(1100, ""),
    G1101(1101, "Token无效"),
    G1102(1102, "权限不足"),
    SUCCESS(0, "成功");

    private static final Map<Integer, ApiResultCode> mapping = new HashMap();
    private final int code;
    private final String message;

    private DefaultApiResultCode(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public static Optional<ApiResultCode> findByCode(Integer code) {
        return Optional.ofNullable((ApiResultCode) mapping.get(code));
    }

    @Override
    public Integer getCode() {
        return this.code;
    }

    @Override
    public String getMessage() {
        return this.message;
    }

    static {
        DefaultApiResultCode[] var0 = values();
        int var1 = var0.length;

        for (int var2 = 0; var2 < var1; ++var2) {
            DefaultApiResultCode resultCode = var0[var2];
            mapping.put(resultCode.getCode(), resultCode);
        }

    }
}
